package com.time.client.application.converter;

import com.time.client.application.dto.PostTimelineItemDTO;
import com.time.client.application.dto.PostTimelineMonthDTO;
import com.time.client.common.entity.PageResult;
import com.time.client.domain.entity.PostTimelineItemBO;
import com.time.client.domain.entity.PostTimelineMonthBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 时间线 DTO 转换器
 */
@Mapper
public interface PostTimelineDTOConverter {

    PostTimelineDTOConverter INSTANCE = Mappers.getMapper(PostTimelineDTOConverter.class);

    PostTimelineItemDTO convertItemBOToDTO(PostTimelineItemBO bo);

    List<PostTimelineItemDTO> convertItemBOListToDTO(List<PostTimelineItemBO> list);

    PostTimelineMonthDTO convertMonthBOToDTO(PostTimelineMonthBO bo);

    List<PostTimelineMonthDTO> convertMonthListToDTO(List<PostTimelineMonthBO> list);

    default PageResult<PostTimelineMonthDTO> convertBOPageToDTOPage(PageResult<PostTimelineMonthBO> boPage) {
        PageResult<PostTimelineMonthDTO> dtoPage = new PageResult<>();
        if (boPage == null) {
            return dtoPage;
        }
        dtoPage.setPageNo(boPage.getPageNo());
        dtoPage.setPageSize(boPage.getPageSize());
        dtoPage.setTotal(boPage.getTotal());
        dtoPage.setTotalPage(boPage.getTotalPage());
        dtoPage.setStart(boPage.getStart());
        dtoPage.setEnd(boPage.getEnd());
        if (boPage.getResult() != null && !boPage.getResult().isEmpty()) {
            dtoPage.setResult(convertMonthListToDTO(boPage.getResult()));
        }
        return dtoPage;
    }
}


